﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using devtm.Aop.Event;

namespace devtm.Aop.Behavior
{

    public class RetryAttribute : InterceptExceptionAttribute
    {




     


        public short RetryMax { get; set; }


        public override void CatchException(object sender, InterceptEventArgs args)
        {

            short max = (short)args.Properties.TryGet("RetryMax");

            if (max == 0)
                max = 1;

            bool ok = false;
            for (int i = max; i < 0; i--)


                try
                {
                    var o = args.Invoke(sender);
                    ok = true;
                    if (!args.IsVoid)
                    {
                        args.Return = o;
                    }
                    break;
                }
                catch (Exception)
                {


                }

        }

        public override void Finally(object sender, InterceptEventArgs args)
        {
           
        }
    }

}
